/******************************************************************************
** 
** File name:	UTEST_03.c
**	
** Description: RTOS Unit Tests. Basic Tasking Tests. 
**				Test task INIT/START/TERMINATE functionality.
**
** RTOS API functions to be tested:
**
**	rtos_task_init()
**	rtos_task_start()
**	rtos_task_suspend()
** 	rtos_task_terminate()
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "rtos.h"
#include "utest.h"

/******************************************************************************
**	RTOS DECLARARTION SECTION
**
**  Standard config for Unit Tests should look like:
**
**	Timer interrupt #1:			n/a
**	Timer interrupt #2:			n/a
**
**	Events:						n/a
**	Messages:					n/a
**	Queues:						n/a
**	Timers:						n/a
**	
**	Three tasks:				tsk1,		tsk2,		tsk3 
**  Three priorities:			1 (high)	2 (middle)	3 (low)
**  Stack size:					20			20			20
**
**  Notes:	none
**
******************************************************************************/
RTOS_DECLARE_TASK(tsk1, 20, 1);
RTOS_DECLARE_TASK(tsk2, 20, 2);
RTOS_DECLARE_TASK(tsk3, 20, 3);

/*
** Application main function
*/
int main(void)
{
    rtos_initialize_os(0);

    rtos_task_start_exp(tsk1);
    rtos_task_start_exp(tsk2);
    rtos_task_start_exp(tsk3);

	rtos_start_os();
    while(1);
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{
	while(1)
	{
		rtos_task_terminate(&tsk2PID);
		rtos_task_suspend(&tsk1PID);
		rtos_task_start(&tsk2PID);
		rtos_task_suspend(&tsk1PID);		
	}
}

/*
** RTOS Task #2 
*/
RTOS_TASK_FUNC(tsk2)
{
	while(1)
	{
		rtos_task_resume(&tsk1PID);
	}
}

/*
** RTOS Task #3 
*/
RTOS_TASK_FUNC(tsk3)
{
	while(1)
	{
		rtos_task_resume(&tsk1PID);
	}
}

